package com.qk.filter;

import jakarta.servlet.*;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {
    // 初始化 - 在服务器启动时调用, 只调用一次, 用来做初始化工作(如:环境准备)
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("DemoFilter...init...");
    }

    // 过滤 - 每次请求时调用, 可调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("DemoFilter...doFilter...");

        //放行
        filterChain.doFilter(servletRequest, servletResponse);
    }

    // 销毁 - 在服务器停止时调用, 只调用一次, 用来做资源清理工作
    @Override
    public void destroy() {
        System.out.println("DemoFilter...destroy...");
    }
}